home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0004_FIBONACC.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  524b  |  27 lines

  1. {
  2. >The problem is to Write a recursive Program to calculate Fibonacci numbers.
  3. >The rules For the Fibonacci numbers are:
  4. >
  5. >    The Nth Fib number is:
  6. >
  7. >    1 if N = 1 or 2
  8. >    The sum of the previous two numbers in the series if N > 2
  9. >    N must always be > 0.
  10. }
  11.  
  12. Function fib(n : LongInt) : LongInt;
  13. begin
  14.   if n < 2 then
  15.     fib := n
  16.   else
  17.     fib := fib(n - 1) + fib(n - 2);
  18. end;
  19.  
  20. Var
  21.   Count : Integer;
  22.  
  23. begin
  24.   Writeln('Fib: ');
  25.   For Count := 1 to 15 do
  26.     Write(Fib(Count),', ');
  27. end.